package de.tabuma.soapforms.soapproject.controller;

import java.io.PrintWriter;
import java.util.*;
import java.util.logging.*;
import de.tabuma.soapforms.*;
import de.tabuma.soapforms.soapproject.logik.*;
import de.tabuma.soapforms.soapproject.entity.*;
import de.tabuma.lib.tabumacontroller;
import javax.servlet.*;
import javax.servlet.http.*;
import com.google.appengine.api.users.*;

/**
 *
 * @author alefen
 */
public class remove extends tabumacontroller {

    public remove(String servlet, Hashtable parameter) {
        super(servlet, parameter);
    }

    @Override
    public void navigate(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
        if(request.getParameter(constants.cancel)!=null) {
            list list = new list(this.getServlet(), this.getParameter());
            list.navigate(context, request, response, out);
            return;
        }

        String soapProjectId = request.getParameter(constants.soapProjectId);
        int spIdInt = Integer.valueOf(soapProjectId);

        if(request.getParameter(constants.removeSoapProject)!=null) {
            SoapProject sp = SoapProjectFacade.get(spIdInt);
            request.setAttribute(constants.soapProject, sp);
            request.setAttribute(constants.soapProjectId, soapProjectId);
            request.setAttribute(constants.removeSoapProject, "true");
            return;
        }

        if(request.getParameter(constants.removeSoapProject1)!=null) {
            SoapProject sp = SoapProjectFacade.get(spIdInt);
            String message = "Soap Project &quot;{1}&quot; successfully removed!";
            if(sp.getWsdlUrl()==null) {
                sp.setWsdlUrl("null");
            }
            message = message.replaceAll("\\{1\\}", sp.getWsdlUrl());
            UserService userService = UserServiceFactory.getUserService();
            User user = userService.getCurrentUser();
            SoapProjectFacade.remove(spIdInt, user.getEmail());
            request.setAttribute(constants.soapProjectSuccessMessage, message);
            list list = new list(this.getServlet(), this.getParameter());
            list.navigate(context, request, response, out);
        }
    }
}
